const fs = require('fs')
let path = require('path')

module.exports = function (req, res, next) {
  let name = req.query.name
  if (name) {
    fs.exists(path.resolve(__dirname, `./pdf/${name}.pdf`), function (exists) {
      if (exists) {
        res.send(`<iframe width="100%" height="100%" src="/pdf/viewer.html?file=/api/pdf/${name}"></iframe>`)
      } else {
        res.send('找不到文件')
      }
    })

  } else {
    res.send('找不到参数')
  }

};